package com.trm.html.servlet;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.alibaba.fastjson.JSONObject;
import com.common.servlet.CommonServlet;
import com.trm.html.dao.CityDao;

public class HtmlServlet extends CommonServlet {

    /**
     * 获得省份信息 mamingyuan 2018年5月28日
     * 
     * @param request
     * @param response
     */
    public void provinceList(HttpServletRequest request, HttpServletResponse response) {
        CityDao cityDao = new CityDao();
        JSONObject json = new JSONObject();
        List<Map<String, Object>> list = cityDao.getProvinceList();
        json.put("id", "provinceid");
        json.put("value", "province");
        json.put("data", list);
        PrintWriter out = null;
        try {
            out = response.getWriter();
            out.print(json.toString());
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            out.close();
        }
    }

    /**
     * 获得城市信息 mamingyuan 2018年6月17日
     * 
     * @param request
     * @param response
     */
    public void cityList(HttpServletRequest request, HttpServletResponse response) {
        CityDao cityDao = new CityDao();
        JSONObject json = new JSONObject();
        List<Map<String, Object>> list = cityDao.getCityList(null);
        json.put("id", "cityid");
        json.put("value", "city");
        json.put("data", list);
        PrintWriter out = null;
        try {
            out = response.getWriter();
            out.print(json.toString());
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            out.close();
        }
    }

    /**
     * 获得地区信息 mamingyuan 2018年6月17日
     * 
     * @param request
     * @param response
     */
    public void areasList(HttpServletRequest request, HttpServletResponse response) {
        CityDao cityDao = new CityDao();
        JSONObject json = new JSONObject();
        List<Map<String, Object>> list = cityDao.getAreasList(null, null);
        json.put("id", "areaid");
        json.put("value", "area");
        json.put("data", list);
        PrintWriter out = null;
        try {
            out = response.getWriter();
            out.print(json.toString());
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            out.close();
        }
    }
}
